# encoding    : utf-8 -*-                            
# @author     :
# @file       :   test.py
# @Time       :   2024/12/11 13:57

import time
from appium import webdriver
from appium.options.common import AppiumOptions
from appium.webdriver.common.appiumby import AppiumBy
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait

caps = {
    "appActivity": ".SplashActivity",
    "platformName": "Android",
    "platformVersion": "12",
    "deviceName": "127.0.0.1:7555",  # 修改为正确的设备名称
    "appPackage": "com.sina.weibo",
    'automationName': 'UiAutomator2'
}

# url = "http://192.168.0.164:4723/wd/hub"  #appium 1.X版本使用，2.X版本不需要/wd/hub
url = "http://127.0.0.1:4723"
options = AppiumOptions().load_capabilities(caps)

driver = webdriver.Remote(url,options=options)
# driver = webdriver.Remote(url,options=options)
# time.sleep(5)

#点击同意按钮
# driver.find_element(AppiumBy.XPATH,"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout[2]/android.widget.LinearLayout/android.widget.TextView[3]").click()
driver.find_element(AppiumBy.XPATH,'//android.widget.TextView[@text="同意并继续"]').click()
# time.sleep(10)

#点击发现
# driver.tap([(713 ,2420)],100)
# time.sleep(5)

#点击我知道了
#点击发现
ele = WebDriverWait(driver,10).until(EC.presence_of_element_located((AppiumBy.XPATH,'(//android.widget.FrameLayout[@content-desc="发现"])[13]')))
# driver.find_element(AppiumBy.XPATH,'(//android.widget.FrameLayout[@content-desc="发现"])[13]').click()
ele.click()

time.sleep(5)
#点击输入框
driver.tap([(460 , 73)],100)
# time.sleep(5)

#输入框输入内容
# driver.find_element(AppiumBy.ID,"com.sina.weibo:id/tv_search_keyword").send_keys("8848")
# 显式等待一个元素出现
search_box = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((AppiumBy.XPATH, '//android.widget.EditText[@resource-id="com.sina.weibo:id/tv_search_keyword"]')))
search_box.send_keys("8848")
# time.sleep(5)


#66 回车
driver.press_keycode(66)
# time.sleep(10)


#第一种方法
for i in range(10):
    # TouchAction(driver).press(x = 1,y = 1).move_to(x = 1,y =5 ).release().perform()
    driver.swipe(start_x=400,start_y=1200,end_x=400,end_y=300,duration=800)
    time.sleep(4)


driver.quit()

